<template>
  <!-- 分配负责人(报价员) -->
  <el-dialog
    v-model="props.modelValue"
    width="800px"
    :show-close="false"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <template #header="{ close, titleId, titleClass }">
      <div class="my-header">
        <h4
          :id="titleId"
          :class="titleClass"
        >
          {{ props.title || t('userCenter.dt1') }}
        </h4>
        <img
          src="@/assets/img/icon_guanbi.png"
          @click="close"
          class="close"
        />
      </div>
    </template>

    <div class="checkList flexcc mt-2">
      <el-radio-group v-model="radioValue">
        <el-radio
          :label="item.id"
          size="large"
          v-for="item in personList"
          >{{ item.userName }} {{ item.customerRoleName }}
        </el-radio>
      </el-radio-group>
    </div>

    <template #footer>
      <div class="dialog-footer flexcc">
        <el-button
          color="#252628"
          plain
          @click="cancel"
        >
          {{ t('cancelText') }}
        </el-button>
        <el-button
          type="primary"
          color="#252628"
          @click="confirm"
        >
          {{ t('confirmText') }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { onBeforeMount, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import useLogin from '@/stores/login'
import { customerListApi } from '@/service/common'
import { headOfDistributionApi as a } from '@/service/dockOrder'
import { headOfDistributionApi as b } from '@/service/procurement'
import { headOfDistributionApi as c } from '@/service/externalAssistance'

const storeLogin = useLogin()

onBeforeMount(() => {
  init()
})

const { t, locale } = useI18n()

const router = useRouter()
const route = useRoute()

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
    required: true
  },
  title: {
    type: String,
    default: ''
  },
  editId: {
    type: Number,
    default: null,
    required: true
  },
  type: {
    type: String,
    required: true
  }
})

const emit = defineEmits(['update:modelValue', 'getList'])

const handleClose = () => {
  emit('update:modelValue')
}

// 取消
const cancel = () => {
  handleClose()
}

// 确定
const confirm = () => {
  const obj = {
    1: a,
    2: b,
    3: c
  }

  obj[props.type]({
    orderId: props.editId,
    quoter: radioValue.value
  }).then(({ msg }) => {
    ElMessage.success(msg)
    handleClose()
    emit('getList')
  })
}

// 人员列表
const personList = ref([])
const getPerconList = () => {
  customerListApi({
    enterpriseId: storeLogin.userInfo.enterpriseId
  }).then(({ rows }) => {
    // personList.value = rows.filter((item) => item.id !== storeLogin.userInfo.id)
    personList.value = rows
  })
}

// 勾选的人员列表
const radioValue = ref(null)

//
const init = () => {
  getPerconList()
}
</script>

<style scoped lang="scss"></style>
